package com.platform.enums;

import com.platform.comm.constants.EnumOption;
import com.platform.comm.enums.IDictEntry;
import com.platform.comm.enums.IEnumItem;
import com.platform.comm.enums.IEnumOption;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Description: 主体类别
 *
 * @author libin Created on 2019/8/19
 **/
@EnumOption(name = "dbpPersonType")
public enum DbpPersonType implements IDictEntry, IEnumItem, IEnumOption<String> {
    /**
     * NAT
     */
    NAT("A01", "clz-dirClassify-sub-sub01", "自然人", "NAT_BASE_INFO"),
    /**
     * LEG
     */
    LEG("A02", "clz-dirClassify-sub-sub02", "法人和非法人组织", "LEG_BASE_INFO");

    @Getter
    public final String typeName;
    @Getter
    public final String codeType;
    @Getter
    public final String text;
    @Getter
    public final String tableName;

    DbpPersonType(String typeName, String codeType, String text, String tableName) {
        this.typeName = typeName;
        this.codeType = codeType;
        this.text = text;
        this.tableName = tableName;
    }


    @Override
    public boolean is(String typeName) {
        return this.typeName.equalsIgnoreCase(typeName);
    }

    @Override
    public String getKey() {
        return this.codeType;
    }

    @Override
    public String getValue() {
        return this.getText();
    }

    @Override
    public Object getData() {
        return this;
    }

    public static DbpPersonType getByTypeName(String typeName) {
        return Stream.of(DbpPersonType.values()).filter(e -> e.getTypeName().equalsIgnoreCase(typeName)).findFirst().orElse(null);
    }

    public static DbpPersonType getByDataBaseType(String codeType) {
        return Stream.of(DbpPersonType.values()).filter(e -> e.getCodeType().equalsIgnoreCase(codeType)).findFirst().orElse(null);
    }

    /**
     * 枚举项 “键”
     *
     * @return key 键
     */
    @Override
    public String key() {
        return this.codeType;
    }

    /**
     * 枚举项 “值”
     *
     * @return value 值
     */
    @Override
    public String value() {
        return this.getText();
    }

    /**
     * 枚举options
     *
     * @return 枚举项组成的map
     */
    @Override
    public Map<String, String> enums() {
        return Arrays.stream(values()).collect(Collectors.toMap(IEnumOption::key, IEnumOption::value));
    }

}
